/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DetailedComplaint.java
 *
 * Created on Sep 4, 2011, 3:19:01 PM
 */

package view;

import control.ComplaintController;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import model.Complaint;

/**
 *
 * @author Bi
 */
public class ComplaintView extends javax.swing.JFrame {

    /** Creates new form DetailedComplaint */
    ArrayList<Complaint> complaintList = new ArrayList<Complaint>();
    private void LoadComplaint(){
        DefaultTableModel table = (DefaultTableModel) tbl_Complain.getModel();
        while (table.getRowCount() > 0) {
            table.removeRow(0);
        }
        Vector row;
        SimpleDateFormat DOBFormat = new SimpleDateFormat("MM/dd/yyyy");

        for (int i = 0; i < complaintList.size(); i++) {
            Complaint _complaint = complaintList.get(i);
            row = new Vector();
            row.addElement(_complaint.getID());
            row.addElement(_complaint.getName());
            row.addElement(_complaint.getAddress());
            row.addElement(_complaint.getPhone());
            row.addElement(_complaint.getEmail());
            row.addElement(_complaint.getType());
            row.addElement(_complaint.getAddress());
            row.addElement(_complaint.getOffTime());
            row.addElement(_complaint.getPlace());
            row.addElement(_complaint.getOfficerID());
            row.addElement(_complaint.getInvovelment());
            row.addElement(_complaint.getDescription());
            row.addElement(_complaint.getComplaintStatus());
            //For Gender column, we must do a gender check
//            if (_complaint.isGender()) {
//                row.addElement("Male");
//            } else {
//                row.addElement("Female");
//            }
//            row.addElement(DOBFormat.format(_complaint.getDateOfBirth()));
//            row.addElement(_complaint.getNationality());
//            row.addElement(_complaint.isIsArrested());
//            //Make sure that null arrested time will not be formatted
//            if (_complaint.getArrestedTime() != null) {
//                row.addElement(ArrestedTimeFormat.format(_complaint.getArrestedTime()));
//            }
            table.addRow(row);
        }
    }
    public ComplaintView() {
        initComponents();
        complaintList =  (ArrayList<Complaint>) ComplaintController.LoadAllComplaint();
        LoadComplaint();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tbl_Complain = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tbl_Complain.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tbl_Complain);

        jButton1.setText("Addnew");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Edit");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Cancel");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(62, 62, 62)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(79, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        EditComplaint editComplaint = new EditComplaint();
        editComplaint.setVisible(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        AddNewComplaint addNewComplaint = new AddNewComplaint();
        addNewComplaint.setVisible(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ComplaintView().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbl_Complain;
    // End of variables declaration//GEN-END:variables

}
